package rak.r91.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import rak.r91.data.User;

public class JdbcUserDao extends JdbcDaoSupport implements UserDao{
	private String USER_STANDARD_QUERY = "SELECT E.employee,UA.user_account, P.first_name, P.last_name FROM employee E INNER JOIN user_account UA ON E.employee = UA.subject_fk " +
  "INNER JOIN person P ON E.person_fk = P.person " +
 "WHERE UA.subject_type_fk = 3  AND UA.username='marten'  AND UA.passw='37b4931088193a73b6561bae19bf06d9'";
	
	@Override
	public List<User> getUser(String username, String Password) {
		return getJdbcTemplate().query( USER_STANDARD_QUERY, new UserMapper());
	}
	
	private static final class UserMapper implements RowMapper<User> {
	    public User mapRow(ResultSet rs, int rowNum) throws SQLException {
	        User user = new User();
	        user.setEmployeeId(rs.getInt("employee"));
	        user.setUserAccount(rs.getInt("user_account"));
	        user.setFirstName(rs.getString("first_name"));
	        user.setLastName(rs.getString("last_name"));
	        return user;
	    }
	}

}
